﻿var cranePic = new Image();
cranePic.src = "png/crane.png";
var backPic = new Image();
backPic.src = "png/back.png";
var productPic = new Image();
productPic.src = "png/product.png";


screenHeight= window.screen.height-10
screenWidth =window.screen.width-10
var allPath=[];
var arrowLineList=[];
storestock = [];//货架位置
craneList=[];
var allCarrierData={}

var testTime=0
var info="asdf";
var stockSize=screenHeight/55;//货位边长
var cols=32


function toX(x){return parseInt(x*30000/screenWidth);}
function toY(y){return parseInt(y*30000/screenHeight);}
function topX(x){return parseInt(x*screenWidth/30000);}
function topY(y){return parseInt(y*screenHeight/30000);}
    
function createCrane(x ,y){
        var craneBegin=x-2.5*stockSize
        var craneEnd=x+(cols+2.5)*stockSize
        craneList.push(new Crane(context,stockSize,{x:craneBegin,y:y},{x:craneEnd,y:y}))
     	  for(var j=0;j<cols;j++){
      		storestock.push(new Product(context,x+j*stockSize,y-stockSize*1.25,stockSize))
      		storestock.push(new Product(context,x+j*stockSize,y+stockSize*1.25,stockSize))
      	}
      	
      	y+=topY(13000);
      	craneList.push(new Crane(context,stockSize,{x:craneBegin,y:y},{x:craneEnd,y:y}))
     	  for(var j=0;j<cols;j++){
      		storestock.push(new Product(context,x+j*stockSize,y-stockSize*1.25,stockSize))
      		storestock.push(new Product(context,x+j*stockSize,y+stockSize*1.25,stockSize))
      	}
	}

function globalLoadfinsh(  context){
    
     var y1=topY(8000)
     var y2=topY(10000)
     var x1=topX(3000)
     var x2=topX(17500)
     createCrane(x1,y1)
     createCrane(x1,y2)
     
     createCrane(x2 ,y1)
     createCrane(x2 ,y2)
     
   
    

	  product1=new Product(context,1000,170,stockSize);


    //动画循环
      (function drawFrame(t){
          window.requestAnimationFrame(drawFrame);
          context.clearRect(0, 0, canvas.width, canvas.height);
          context.fillStyle="#0ff";
          context.fillRect(0,0,canvas.width,canvas.height);
          myDraw(context);
          
          for(var i=0;i<allPath.length;i++){
				     	 var path=		allPath[i]
		     			 var  task = pathTask[path.id] ;
		     			 if(task){
		     			 	  context.font="15px 宋体";
		     			 	  context.fillStyle ="#0ff"
		     			 	  context.fillText(task,path.x-1,path.y+4);
		     			 }
		     }
      }());
	}








  



      function myDraw(context){

      	 context.drawImage(backPic,0,0,canvas.width, canvas.height)
      	 	for(var i=0;i<storestock.length;i++){
        		storestock[i].draw();
        	}

		     for(var i=0;i<allPath.length;i++){
				     	 var yzj=		allPath[i]
		     			 yzj.draw();
		     }
				if(keyClickStatus[76])
 				for(var i=0;i<arrowLineList.length;i++){
				     	 var yzj=		arrowLineList[i]
		     			 yzj.draw();
		     }


		    for(var i=0;i<craneList.length;i++){
				     	 var crane1=		craneList[i]
		     			 crane1.draw();
		    }
        product1.setAnchor(crane1.getAnchor());
        product1.draw();
		    var arr =  carrierTaskRun.getAllAnthor();
   			for(var i=0;i<arr.length;i++){
   				 var p=new Product(context,68*i,170,stockSize);
   				 p.setAnchor(arr[i])
   				 p.draw();
   			}
   			
   			/*
   			context.beginPath();
   			
   			var s=selectKeyID
   		  if(selectCarrierChain&&selectCarrierChain.id){
   				s+="select"+selectCarrierChain.id
   			}
   		
		    context.font="20px Georgia";
	    	context.fillText(s, 117, 177);
	    	*/
      }

   


    	
    







